package com.tonghe.service.bill;

import com.tonghe.dao.BaseDao;
import com.tonghe.dao.bill.BillDao;
import com.tonghe.dao.bill.BillDaoImpl;
import com.tonghe.pojo.Bill;
import com.tonghe.service.user.UserServiceImpl;
import org.junit.Test;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

/**
 * @Date:2021/12/12- 12- 12- 13:49
 **/
public class BillServiceImpl implements BillService{

    private BillDao billDao;
    public BillServiceImpl(){
        billDao = new BillDaoImpl();
    }

    @Override
    public List<Bill> getBillList(Bill bill) {
        Connection connection = null;
        List<Bill> billList = null;
//        System.out.println("query productName ---- > " + bill.getProductName());
//        System.out.println("query providerId ---- > " + bill.getProviderId());
//        System.out.println("query isPayment ---- > " + bill.getIsPayment());

        try {
            // 1、获取数据库连接对象
            connection = BaseDao.getConnection();
            // 2、到数据库中查询并得到对象
            billList = billDao.getBillList(connection, bill);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            // 3、关闭数据库连接资源
            BaseDao.closeResource(connection, null, null);
        }
        // TODO 查询到的数据为空怎么办？
        // TODO 前端工程不需要这么多数据，一些不必要的数据被返回到前端
        // 4、返回数据对象
        return billList;
    }
    @Test
    public void test1(){
        List<Bill> billList = new ArrayList<Bill>();
        BillServiceImpl billService = new BillServiceImpl();
        billList = billService.getBillList(null);
        System.out.println(billList);
    }
}
